package com.yixing.tech.entity.entity.attr;

import com.yixing.tech.common.base.BusinessException;
import com.yixing.tech.common.vo.s5.EntitySchema;
import org.springframework.data.mongodb.core.aggregation.*;

import java.util.List;

/**
 * @author yixing tech
 * at 2021/10/9
 * describe：
 */
public final class SingleText extends AttrType {
    public SingleText() {
        super("单行文本", "singleText");
    }


    /**
     * 数据检索处理
     *
     * @param operations
     * @param attr
     * @throws BusinessException
     */
    @Override
    public void out(List<AggregationOperation> operations, EntitySchema.AttrVO attr) throws BusinessException {
        super.out(operations, attr);
//        String format = attr.getValueFormat();
//        if ("百分比".equals(format)) {
//            ArithmeticOperators.Multiply multiply = ArithmeticOperators.Multiply.valueOf(ConvertOperators.ToDecimal.toDecimal("$"+attr.getCode())).multiplyBy(100);
//            operations.add(Aggregation.addFields().addFieldWithValue(attr.getCode(), StringOperators.Concat.valueOf(ConvertOperators.ToString.toString(ConvertOperators.ToDouble.toDouble(multiply))).concat("%")).build());
//        }

    }

    /**
     * 数据插入处理
     *
     * @param source
     * @param attr
     * @return
     * @throws BusinessException
     */
    @Override
    public Object in(Object source, EntitySchema.AttrVO attr) throws BusinessException {
        return String.valueOf(source);
    }
}
